package com.fpost.manager;

import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;

import com.fpost.dao.impl.ArticleDAO;
import com.fpost.domain.Article;
import com.fpost.domain.User;

public class ArticleManager {
	
	public Long save(Article article) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.save(article);		
	}
	
	@Deprecated
	public void saveArticles(List<Article> articles) {
		ArticleDAO dao = new ArticleDAO();
		dao.saveArticles(articles);
	}

	public void saveOrUpdate(Article article) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		dao.saveOrUpdate(article);
	}

	public void delete(long id) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		dao.delete(id);
		
	}

	public Article get(long id) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.get(id);
	}
	
	public long getUserIdByArticleId(long articleId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getUserIdByArticleId(articleId);
	}
	
	@Deprecated
	@SuppressWarnings("unchecked")
	public List<Article> getCurrentArticlesByUserId_HQL(long userId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByUserId_HQL(userId);
	}
	
	public Article getArticleById(long articleId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getArticleById(articleId);
	}
	
	public Article getArticleByIdIncrementHitCount(long articleId, String ipAddress) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getArticleByIdIncrementHitCount(articleId, ipAddress);
	}

	@SuppressWarnings("unchecked")
	public List<Article> getCurrentArticlesByUser(User user) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByUser(user);
	}
	@SuppressWarnings("unchecked")
	public List<Article> getDeletedArticlesByUser(User user) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getDeletedArticlesByUser(user);
	}
	@SuppressWarnings("unchecked")
	public List<Article> getAllArticlesByUser(User user) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllArticlesByUser(user);
	}
	
	@SuppressWarnings("unchecked")
	public long countCurrentArticlesByUsername_HQL(String username) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.countCurrentArticlesByUsername_HQL(username);
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getCurrentArticlesByUsername(String username) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByUsername(username);
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getDeletedArticlesByUsername(String username) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getDeletedArticlesByUsername(username);
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getAllArticlesByUsername(String username) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllArticlesByUsername(username);
	}
	
	public boolean isCurrentArticleExists(long articleId) {
		ArticleDAO dao = new ArticleDAO();
		return dao.isCurrentArticleExists(articleId);
	}
	
	@SuppressWarnings("unchecked")
	public long countCurrentArticlesByUserId_HQL(long userId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.countCurrentArticlesByUserId_HQL(userId);
	}	
	
	@SuppressWarnings("unchecked")
	public List<Article> getCurrentArticlesByUserId(long userId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByUserId(userId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getDeletedArticlesByUserId(long userId) {
		ArticleDAO dao = new ArticleDAO();
		return dao.getDeletedArticlesByUserId(userId);		
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getAllArticlesByUserId(long userId) {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllArticlesByUserId(userId);		
	}
	
	@Deprecated
	@SuppressWarnings("unchecked")
	public List<Article> getArticlesByInputKeyCrit(String inputKey) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getArticlesByInputKeyCrit(inputKey);
	}
	
	public List<Article> getMostRecentCurrentArticles(int maxResult) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getMostRecentCurrentArticles(maxResult);
	}
	
	public List<Article> getMostRecentCurrentArticles(Date from, Date to, int maxResult) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getMostRecentCurrentArticles(maxResult);
	}
	
	public List<Article> getMostPopularCurrentArticles(int maxResult) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getMostPopularCurrentArticles(maxResult);
	}
	
	public List<Article> getMostPopularCurrentArticles(Date from, Date to, int maxResult) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getMostPopularCurrentArticles(from, to, maxResult);
	}	
	
	@SuppressWarnings("unchecked")
	public long countCurrentArticlesByInputAndType_HQL(String inputKey, long articleTypeId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.countCurrentArticlesByInputAndType_HQL(inputKey, articleTypeId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getCurrentArticlesByInputAndType_HQL(String inputKey, long articleTypeId) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByInputAndType_HQL(inputKey, articleTypeId);
	}
	
	public List<Article> getCurrentArticlesByArticleIds(List<Long> articleIds) {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesByArticleIds(articleIds);		
	}
	
	public List<Long> selectArticleIdsByArticleTypeId_HQL(List<Long> articleIds, long articleTypeId) {
		ArticleDAO dao = new ArticleDAO();
		return dao.selectArticleIdsByArticleTypeId_HQL(articleIds, articleTypeId);		
	}
	
	public List<Article> getCurrentArticles(int maxResults) {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticles(maxResults);		
	}
	
	public List<Article> getCurrentArticlesWithHitCountMoreThan_HQL(long hitCount) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getCurrentArticlesWithHitCountMoreThan_HQL(hitCount);	
	}
	
	public List<Object[]> getHighestRatingCurrentArticles_SQL(java.sql.Date from, java.sql.Date to, int maxResults) throws HibernateException {
		ArticleDAO dao = new ArticleDAO();
		return dao.getHighestRatingCurrentArticles_SQL(from, to, maxResults);
	}
	
	public List<Article> getAllCurrentArticles() {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllCurrentArticles();		
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getAllDeletedArticles() {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllDeletedArticles();		
	}
	
	@SuppressWarnings("unchecked")
	public List<Article> getAllArticles() {
		ArticleDAO dao = new ArticleDAO();
		return dao.getAllArticles();		
	}	
}
